package com.me.myFramework.aop22.aop122.intercept.method;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.AfterReturningAdvice;

/**
 * 《AOP-122》：  <br><br>
 *
 * MethodInterceptor 不直接调用目标方法，统一委托给 MethodInvocation（执行器）
 *
 * @author ME
 */
public class AfterReturningAdviceInterceptor122 implements MethodInterceptor {

    private final AfterReturningAdvice advice;

    public AfterReturningAdviceInterceptor122(AfterReturningAdvice advice) {
        this.advice = advice;
    }

    @Override
    public Object invoke(MethodInvocation mi) throws Throwable {
        Object retVal = mi.proceed();
        this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());

        return retVal;
    }

}
